package br.com.main.client.system;

import br.com.main.client.system.SistemaPresenter.Display;
import br.com.main.client.system.botoes.AreaLazerPresenter;
import br.com.main.client.system.botoes.FinanceiroPresenter;
import br.com.main.client.system.botoes.MeusDadosPresenter;
import br.com.main.client.system.botoes.MeusDadosView;
import br.com.main.client.system.botoes.NotificacoesPresenter;
import br.com.main.client.system.botoes.NotificacoesView;
import br.com.main.client.system.botoes.ReservasPresenter;
import br.com.main.client.system.botoes.ReservasView;
import br.com.main.client.system.botoes.MoradoresPresenter;
import br.com.main.client.system.botoes.MoradoresView;
import br.com.main.client.system.botoes.AreaLazerView;
import br.com.main.client.system.botoes.HomeView;
import br.com.main.client.system.botoes.FinanceiroView;
import br.com.main.client.system.morador.AreaLazerViewM;
import br.com.main.client.system.morador.FinanceiroPresenterM;
import br.com.main.client.system.morador.FinanceiroViewM;
import br.com.main.client.system.morador.HomeViewM;
import br.com.main.client.system.morador.MeusDadosPresenterM;
import br.com.main.client.system.morador.MeusDadosViewM;
import br.com.main.client.system.morador.NotificacoesPresenterM;
import br.com.main.client.system.morador.NotificacoesViewM;
import br.com.main.client.system.morador.ReservasPresenterM;
import br.com.main.client.system.morador.ReservasViewM;

import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.DeckPanel;
import com.google.gwt.user.client.ui.DockPanel;
import com.google.gwt.user.client.ui.VerticalPanel;

public class SistemaView extends Composite implements Display {

	private VerticalPanel painelMain;
	private DockPanel painelBorda;
	private VerticalPanel painelBotoes;
	private Button[] botoes;
	private DeckPanel deck;
	
	private int modulo;

	public SistemaView(int modulo) {
		this.modulo = modulo;
		init();
		initWidget(painelMain);
	}

	private void init() {
		painelMain = new VerticalPanel();
		painelMain.addStyleName("borda");
		painelMain.addStyleName("bordaSystem");
		painelMain.setSize("1200px", "350px");
		painelBorda = new DockPanel();
		painelBorda.setSpacing(20);

		painelBotoes = new VerticalPanel();
		
		deck = new DeckPanel();

		if (modulo == 0) {	// sindico
			botoes = new Button[8];

			String[] nomesBotoes = { "Home", "Moradores", "Finanças", "Area de Lazer", "Meus Dados",
					"Reservas","Notificações", "Logout" };
			for (int i = 0; i < nomesBotoes.length; i++) {
				botoes[i] = new Button(nomesBotoes[i]);
				botoes[i].addStyleName("botoesSistema");
				painelBotoes.add(botoes[i]);
			}
			
			MoradoresView mv = new MoradoresView();
			new MoradoresPresenter(mv);
			
			MeusDadosView mdv = new MeusDadosView();
			new MeusDadosPresenter(mdv,deck);
			
			AreaLazerView alv = new AreaLazerView();
			new AreaLazerPresenter(alv);
			
			ReservasView rv = new ReservasView();
			new ReservasPresenter(rv);
			
			FinanceiroView fc = new FinanceiroView();
			new FinanceiroPresenter(fc);
			
			NotificacoesView ntv = new NotificacoesView();
			new NotificacoesPresenter(ntv, deck);
			
			deck.add(new HomeView());
			deck.add(mv);
			deck.add(fc);
			deck.add(alv);
			deck.add(mdv);
			deck.add(rv);
			deck.add(ntv);
			
		} else {	// modulo == 1 (morador)
			botoes = new Button[6];

			String[] nomesBotoes = { "Home", "Finanças", "Meus Dados",
					"Reservas","Notificações", "Logout" };
			for (int i = 0; i < nomesBotoes.length; i++) {
				botoes[i] = new Button(nomesBotoes[i]);
				botoes[i].addStyleName("botoesSistema");
				painelBotoes.add(botoes[i]);
			}
			
			FinanceiroViewM fv = new FinanceiroViewM();
			new FinanceiroPresenterM(fv);
			
			MeusDadosViewM mdv = new MeusDadosViewM();
			new MeusDadosPresenterM(mdv, deck);
			
			ReservasViewM rv = new ReservasViewM();
			new ReservasPresenterM(rv);
			
			NotificacoesViewM nv = new NotificacoesViewM();
			new NotificacoesPresenterM(nv);
			
			deck.add(new HomeViewM());
			deck.add(fv);
			deck.add(mdv);
			deck.add(rv);
			deck.add(nv);
		}
		
		botoes[0].setStyleName("botaoClicado", true);
		deck.showWidget(0);
		deck.setSize("100%", "100%");
		deck.setAnimationEnabled(true);
		
		painelBorda.add(painelBotoes, DockPanel.WEST);
		painelBorda.add(deck, DockPanel.CENTER);

		painelMain.add(painelBorda);
	}

	@Override
	public DeckPanel getDeck() {
		return deck;
	}

	@Override
	public Button[] getBotoes() {
		return botoes;
	}

}
